package com.piggy.logi.sys.controller;

import com.piggy.common.core.utils.poi.ExcelUtil;
import com.piggy.common.core.web.controller.BaseController;
import com.piggy.common.core.web.page.TableDataInfo;
import com.piggy.common.log.annotation.LogiLog;
import com.piggy.common.log.enums.BusinessType;
import com.piggy.common.satoken.utils.SecurityUtils;
import com.piggy.logi.sys.bo.LogiBranchBusStatisticsQueryBo;
import com.piggy.logi.sys.bo.LogiCustomerBusStatisticsQueryBo;
import com.piggy.logi.sys.bo.LogiProjectBusStatisticsQueryBo;
import com.piggy.logi.sys.bo.LogiTransportBusStatisticsQueryBo;
import com.piggy.logi.sys.service.ILogiBusinessStatisticsService;
import com.piggy.logi.sys.vo.LogiBranchBusStatisticsVo;
import com.piggy.logi.sys.vo.LogiCustomerBusStatisticsVo;
import com.piggy.logi.sys.vo.LogiProjectBusStatisticsVo;
import com.piggy.logi.sys.vo.LogiTransportBusStatisticsVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 业务统计Controller
 *
 * @author fengxy
 * @date 2023/10/17 21:28
 **/
@Api(value = "业务统计控制器", tags = {"业务统计"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/sys/business/statistics")
public class LogiBusinessStatisticsController extends BaseController {

    private final ILogiBusinessStatisticsService iLogiBusinessStatisticsService;

    /**
     * 客户业务统计
     */
    @ApiOperation("客户业务统计")
    //@SaCheckPermission("sys:business:statistics:customer")
    @PostMapping("/customer")
    public TableDataInfo<LogiCustomerBusStatisticsVo> customer(@Validated @RequestBody LogiCustomerBusStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiBusinessStatisticsService.customerStatisticsPage(bo);
    }

    /**
     * 客户业务统计导出
     */
    @ApiOperation("客户业务统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:business:statistics:customer:export')")
    @LogiLog(title = "业务统计", businessType = BusinessType.EXPORT)
    @PostMapping("/customer/export")
    public void customerExport(@Validated @RequestBody LogiCustomerBusStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiCustomerBusStatisticsVo> list = iLogiBusinessStatisticsService.customerStatisticsList(bo);
        ExcelUtil<LogiCustomerBusStatisticsVo> util = new ExcelUtil<>(LogiCustomerBusStatisticsVo.class);
        util.exportExcel(response, list, "客户业务统计");
    }

    /**
     * 项目业务统计
     */
    @ApiOperation("项目业务统计")
    //@SaCheckPermission("sys:business:statistics:project")
    @PostMapping("/project")
    public TableDataInfo<LogiProjectBusStatisticsVo> project(@Validated @RequestBody LogiProjectBusStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiBusinessStatisticsService.projectStatisticsPage(bo);
    }

    /**
     * 项目业务统计导出
     */
    @ApiOperation("项目业务统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:business:statistics:project:export')")
    @LogiLog(title = "业务统计", businessType = BusinessType.EXPORT)
    @PostMapping("/project/export")
    public void projectExport(@Validated @RequestBody LogiProjectBusStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiProjectBusStatisticsVo> list = iLogiBusinessStatisticsService.projectStatisticsList(bo);
        ExcelUtil<LogiProjectBusStatisticsVo> util = new ExcelUtil<>(LogiProjectBusStatisticsVo.class);
        util.exportExcel(response, list, "项目业务统计");
    }

    /**
     * 网点业务统计
     */
    @ApiOperation("网点业务统计")
    //@SaCheckPermission("sys:business:statistics:branch")
    @PostMapping("/branch")
    public TableDataInfo<LogiBranchBusStatisticsVo> branch(@Validated @RequestBody LogiBranchBusStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiBusinessStatisticsService.branchStatisticsPage(bo);
    }

    /**
     * 网点业务统计导出
     */
    @ApiOperation("网点业务统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:business:statistics:branch:export')")
    @LogiLog(title = "业务统计", businessType = BusinessType.EXPORT)
    @PostMapping("/branch/export")
    public void branchExport(@Validated @RequestBody LogiBranchBusStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiBranchBusStatisticsVo> list = iLogiBusinessStatisticsService.branchStatisticsList(bo);
        ExcelUtil<LogiBranchBusStatisticsVo> util = new ExcelUtil<>(LogiBranchBusStatisticsVo.class);
        util.exportExcel(response, list, "网点业务统计");
    }

    /**
     * 货物运输统计
     */
    @ApiOperation("货物运输统计")
    //@SaCheckPermission("sys:business:statistics:transport")
    @PostMapping("/transport")
    public TableDataInfo<LogiTransportBusStatisticsVo> transport(@Validated @RequestBody LogiTransportBusStatisticsQueryBo bo) {
        bo.setDeptId(SecurityUtils.getDeptId());
        return iLogiBusinessStatisticsService.transportStatisticsPage(bo);
    }

    /**
     * 货物运输统计导出
     */
    @ApiOperation("货物运输统计导出")
//    @SaCheckPermission("@ss.hasPermi('sys:business:statistics:transport:export')")
    @LogiLog(title = "业务统计", businessType = BusinessType.EXPORT)
    @PostMapping("/transport/export")
    public void transportExport(@Validated @RequestBody LogiTransportBusStatisticsQueryBo bo, HttpServletResponse response) throws IOException {
        bo.setDeptId(SecurityUtils.getDeptId());
        List<LogiTransportBusStatisticsVo> list = iLogiBusinessStatisticsService.transportStatisticsList(bo);
        ExcelUtil<LogiTransportBusStatisticsVo> util = new ExcelUtil<>(LogiTransportBusStatisticsVo.class);
        util.exportExcel(response, list, "货物运输统计");
    }
}
